349A codeforces solution in cpp
by ujjal roy
#include<bits/stdc++.h>
using namespace std;
main()
{
int n,tf=0,f=0,i,c=0;
cin>>n;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
if(a[i]==25)
{
tf++;
continue;
}
if(a[i]==50)
{
f++;
if(tf==0)
{
c=1;
}
else
{
tf--;
}
}
if(a[i]==100)
{
if(f==0)
{
if(tf*25>=75)
{
tf-=3;
}
else c=1;
}
else
{
if(tf<=0) c=1;
else
{
tf--;
f--;
}
}
}
if(c==1) break;
}
if(c==0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
0 Comments